﻿using UnityEngine;
using System.Collections;

public class SmoothFollower2 : MonoBehaviour {

	public Transform target;
	
	public float distanceToTarget;
	public float distanceToShip;
	public float height;
	public float rotationDamping;
	public float heightDamping;
	
	// Use this for initialization
	void Start () {
		transform.position = target.position - target.forward *distanceToShip;
		transform.position += target.up * height;
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		Vector3 newPosition = target.position - target.forward *distanceToShip + target.up * height;
		transform.position = Vector3.Lerp(transform.position, newPosition, Time.deltaTime*heightDamping);
		Quaternion targetRotation = Quaternion.LookRotation((target.position + target.transform.forward * distanceToTarget) - transform.position, target.up);
		transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 10);
	}
}
